//
//  AY_BookVpHeader.m
//  AiYue
//
//  Created by boWen on 2023/10/26.
//

#import "AY_BookVpHeader.h"
#import "AY_BookVpStackView.h"

@interface AY_BookVpHeader ()
@property (nonatomic, strong) UIView * bg_View;
@property (nonatomic, strong) UIImageView * vp_ImageView;
@property (nonatomic, strong) UILabel * nameLabel;
@property (nonatomic, strong) UILabel * jieshengLabel;
@property (nonatomic, strong) UIStackView * stackView;
@property (nonatomic, strong) AY_BookVpStackView * qccdView;
@property (nonatomic, strong) AY_BookVpStackView * yytsView;
@property (nonatomic, strong) AY_BookVpStackView * jbfbView;
@property (nonatomic, strong) AY_BookVpStackView * zskfView;
@property (nonatomic, strong) AY_BookVpStackView * zgsfView;

@end

@implementation AY_BookVpHeader

- (instancetype)initWithFrame:(CGRect)frame {
    if([super initWithFrame:frame]) {
        self.bg_View = [AYTool createViewWithFrame:CGRectZero andBg:COLOR(@"#19171A") andRadius:YNUM(1) andAddSubView:self];
        [self.bg_View mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.equalTo(self);
        }];
        
        self.vp_ImageView = [AYTool createImageViewWithFrame:CGRectZero andImage:YImage(@"icon_noVp_own") andBg:nil  andRadius:0.0 andAddSubView:self.bg_View];
        self.vp_ImageView.contentMode =  UIViewContentModeScaleAspectFit;
        [self.vp_ImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(self.bg_View).offset(YNUM(12));
            make.right.equalTo(self.bg_View).offset(YNUM(-12));
            make.height.mas_offset(YNUM(123));
        }];
                
        self.jieshengLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#814b1d") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(12)] andLines:1 andRadius:0 andAddSubView:self.vp_ImageView];
        [self.jieshengLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.vp_ImageView).offset(YNUM(18));
            make.bottom.equalTo(self.vp_ImageView).offset(YNUM(-15));
        }];
        
        self.nameLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#814b1d") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(16)] andLines:1 andRadius:0 andAddSubView:self.vp_ImageView];
        [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.vp_ImageView).offset(YNUM(18));
            make.bottom.equalTo(self.jieshengLabel.mas_top).offset(YNUM(-15));
        }];
        
        
        self.qccdView = [[AY_BookVpStackView alloc] initWithFrame:CGRectZero];
        self.qccdView.downLabel.text = @"全场畅读";
        self.qccdView.topImgView.image = YImage(@"icon_qccd_p.png");
        
        self.yytsView = [[AY_BookVpStackView alloc] initWithFrame:CGRectZero];
        self.yytsView.downLabel.text = @"语音听书";
        self.yytsView.topImgView.image = YImage(@"icon_yyts_p.png");

        self.jbfbView = [[AY_BookVpStackView alloc] initWithFrame:CGRectZero];
        self.jbfbView.downLabel.text = @"金币翻倍";
        self.jbfbView.topImgView.image = YImage(@"icon_jbfb_p.png");

        self.zskfView = [[AY_BookVpStackView alloc] initWithFrame:CGRectZero];
        self.zskfView.downLabel.text = @"专属客服";
        self.zskfView.topImgView.image = YImage(@"icon_zskf_p.png");
        
        self.zgsfView = [[AY_BookVpStackView alloc] initWithFrame:CGRectZero];
        self.zgsfView.downLabel.text = @"尊贵身份";
        self.zgsfView.topImgView.image = YImage(@"icon_zgsf_p.png");

        
        self.stackView = [[UIStackView alloc] initWithArrangedSubviews:@[self.qccdView, self.yytsView, self.jbfbView, self.zskfView, self.zgsfView]];
        [self.bg_View addSubview:self.stackView];
        [self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.left.equalTo(self.vp_ImageView);
            make.bottom.equalTo(self.bg_View);
            make.height.mas_offset(YNUM(95));
        }];
        self.stackView.distribution = UIStackViewDistributionFillEqually;
        self.stackView.axis = UILayoutConstraintAxisHorizontal;
        self.stackView.spacing = 4;
        
    }
    return self;
}

- (void)setVpModel:(VpProductModel *)vpModel {
    _vpModel = vpModel;
    if(vpModel.oriPrice.integerValue > 200) {//年
        self.vp_ImageView.image = YImage(@"icon_year_own");
        self.nameLabel.textColor = COLOR(@"e5d59f");
        self.jieshengLabel.textColor = COLOR(@"e5d59f");
    }else {//月
        self.vp_ImageView.image = YImage(@"icon_month_own");
        self.nameLabel.textColor = COLOR(@"814b1d");
        self.jieshengLabel.textColor = COLOR(@"814b1d");
    }
}

- (void)setInfoModel:(UserInfo *)infoModel {
    self.nameLabel.text = infoModel.nickName;
    if([infoModel.vipFlag isEqual:@"1"]) {
        if([kStringUtils(self.vipType) isEqualToString:@"3"]) {//年
            self.vp_ImageView.image = YImage(@"icon_year_own");
            self.nameLabel.textColor = COLOR(@"e5d59f");
            self.jieshengLabel.textColor = COLOR(@"e5d59f");
        }else {
            self.nameLabel.textColor = COLOR(@"814b1d");
            self.jieshengLabel.textColor = COLOR(@"814b1d");
            self.vp_ImageView.image = YImage(@"icon_month_own");
        }
        if (!kStringIsEmpty(_infoModel.vipEndTime)) {
            NSString *time = [_infoModel.vipEndTime stringByReplacingOccurrencesOfString:@"T" withString:@" "];
            self.jieshengLabel.text = [NSString stringWithFormat:@"到期时间：%@", time];
        }
    }else {
        self.jieshengLabel.text = @"全场图书免费阅读，无需额外付费";
        self.vp_ImageView.image = YImage(@"icon_month_own");
    }
}

@end
